package com.bjb.vr.manager.controller;

import com.alibaba.fastjson.JSONArray;
import com.bjb.vr.common.constant.ServerModeConstant;
import com.bjb.vr.common.result.BaseResult;
import com.bjb.vr.common.result.CommonResult;
import com.bjb.vr.common.service.SysUpgradeService;
import com.bjb.vr.manager.properties.ServerInfoProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @version 1.0.0
 * @description:系统升级
 * @author: caihaibo
 * @createDate: 2022/8/3
 */
@Slf4j
@RestController
@RequestMapping("/api/manager/v1")
public class SysUpgradeController {

    @Resource
    SysUpgradeService sysUpgradeService;

    @Resource
    ServerInfoProperties serverInfoProperties;


    /**
     * 获取前置机最新版本更新信息
     */
    @PostMapping("/queryLatestVersion")
    public BaseResult queryLatestVersion() {
        // 判断服务部署类型
        if (ServerModeConstant.LOCAL.equals(serverInfoProperties.getDeployMode())) {
            JSONArray array = sysUpgradeService.queryLatestVersion();
            return CommonResult.Ok().setResult(array);
        } else {
            return CommonResult.Ok("当前服务类型为【云端服务】,请使用Jenkins发布！");
        }
    }

}
